//
//  Common.m
//  SuperLight
//
//  Created by Charlie Liao on 14-4-29.
//  Copyright (c) 2014年 Charlie Liao. All rights reserved.
//

#import "Common.h"

#define kLightsArr    @"kLightsArr"

@implementation Common

#pragma mark  Init

+ (Common *)share
{
    static Common *singleton;
    if (!singleton) {
        @synchronized(self) {
            singleton = [[super allocWithZone:NULL] init];
        }
    }
    return singleton;
}

+ (id)allocWithZone:(struct _NSZone *)zone
{
   return [Common share];
}

- (id)init
{
    self = [super init];
    if (self) {
        NSData *data = [[NSUserDefaults standardUserDefaults] dataForKey:kLightsArr];
        
        self.lightsArr = [NSMutableArray arrayWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:data]];
    }
    return self;
}

#pragma mark 


- (void)saveLightsArr
{
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.lightsArr];
    
    [[NSUserDefaults standardUserDefaults] setObject:data forKey:kLightsArr];
}

@end
